package cn.itcast.controller;

import cn.itcast.client.StudentClient;
import cn.itcast.pojo.Student;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;

@RestController
@RequestMapping("stu")
@DefaultProperties(defaultFallback = "defaultFallBack")
public class StudentController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private StudentClient studentClient;
    @GetMapping("f/{id}")
    public Student findTne(@PathVariable("id") String id){
        return studentClient.findTne(id);
    }
    

//    @RequestMapping("{id}")
//    @HystrixCommand
//    @HystrixCommand
//    public Student findOne(@PathVariable("id") String id){
//        Student object = restTemplate.getForObject("http://127.0.0.1:8081/user/"+id, Student.class);
//        return object;
//        List<ServiceInstance> instances = discoveryClient.getInstances("user-service");
//        ServiceInstance serviceInstance = instances.get(0);
//        String url="http://user-service/user/"+id;
//        Student forObject = restTemplate.getForObject(url, Student.class);
//        return forObject;
//
//    }
//    public Student defaultMethod(String id){
//        Student student = new Student();
//        student.setSname("错误");
//        return student;
//    }


}
